<template>
	<view>
		<home :cur="PageCur"  v-if="PageCur=='home'" :key="commponent1Key"></home>
		<people ref="people" :cur="PageCur" v-if="PageCur=='people'" :key="commponent2Key"></people>
		<view class="cu-bar tabbar bg-white shadow foot">
			<view :class="PageCur=='home'?'action text-green':'action text-black'" @click="NavChange" data-cur="home">
				<view class='iconfont icon-shouye text-xxxl'></view><text class="text-df">主页</text>
			</view>
			<view class="action text-black" @click="goPage('nswd')" data-cur="nswd">
				<view class='iconfont icon-xiaoxi text-xxxl'></view><text class="text-df">问答</text>
			</view>
			<view class="action text-green" @click="goPage('nswd_publish')" data-cur="nswd_publish">
				<button class="cu-btn cuIcon-add bg-green shadow"></button>
				<text class="text-df">提问</text>
			</view>
			<view class="action text-black" @click="goPage('bhzd')" data-cur="bhzd">
				<view class='iconfont icon-wenzhen text-xxxl'></view><text class="text-df">病害</text>
			</view>
			<view :class="PageCur=='people'?'action text-green':'action text-black'" @click="NavChange" data-cur="people">
				<view class='iconfont icon-wode text-xxxl'></view><text class="text-df">我的</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				PageCur: 'home',
				commponent1Key: 0,
				commponent2Key: 0
			}
		},
		onLoad: function(option) {
			this.PageCur = 'home'
				++this.commponent1Key
				++this.commponent2Key
			var this_ = this;
			//添加监听刷新事件
			uni.$on('reloadPsnInfo', function(data) {
				// console.log('监听到事件来自 reloadPsnInfo ，携带参数 msg 为：' + data.msg);
				this_.getChildMethod();
			})
		},
		onReady() {
			// 检测升级
			this.checkVersion()
		},
		methods: {
			NavChange: function(e) {
				this.PageCur = e.currentTarget.dataset.cur
			},
			//调用子组件方法
			getChildMethod() {
				this.$refs.people.getUserInfo(); //ref="people"
			},
			goPage(page) {
				if (!page) {
					return false;
				}
				this.$Router.push({
					name: page
				})
			},
			//检测版本
			checkVersion() {
				//#ifdef APP-PLUS  
				let _this=this;
				uni.request({
					url: _this.$config.apiUrl + "/appVersionController/version", //检查更新的服务器地址
					data: {
						appid: plus.runtime.appid,
						version: plus.runtime.version,
						imei: plus.device.imei
					},
					success: (res) => {
						plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
							let versionInfo = res.data.data;
							let statusCode = res.statusCode;
							let client_version = wgtinfo.version
							// console.log(client_version)
							// console.log(versionInfo.status)
							// console.log(versionInfo.url)

							let flag_update = statusCode == '200' && versionInfo != null && versionInfo.status == '1';
							if (flag_update) {
								// 提醒用户更新
								uni.showModal({
									title: "更新提示",  
									content: versionInfo.note,  
									success: (res) => {  
										if (res.confirm) {  
											plus.runtime.openURL(_this.$config.imgUrl+'/'+versionInfo.url);  
										}  
									}  
								})  
							}
						});
					}
				})
				//#endif  
			}
		}
	}
</script>

<style>

</style>
